package com.Ling.Thread.sync;

/**
 * File Name: SourceConflict
 * Date: 2020-06-24 16:34
 * Author: liangling
 * Description
 */
public class SourceConflict {


    public static void main(String[] args) {
        Runnable r = ()->{
            while (TicketCenter.ticketCount>0){
                synchronized (""){
                    if (TicketCenter.ticketCount<=0){
                        return;
                    }
                    System.out.println(Thread.currentThread().getName()+"卖出一张票，剩余"+ --TicketCenter.ticketCount+" 张");
                }

            }
        };
        Thread t1 = new Thread(r,"thread-1");
        Thread t2 = new Thread(r,"thread-2");
        Thread t3 = new Thread(r,"thread-3");
        Thread t4 = new Thread(r,"thread-4");

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}

class TicketCenter{
    public static int ticketCount =100;
}